package com.wyw.leetcode.learning.simple;

import java.util.ArrayList;
import java.util.List;

/**
 * leetcode topic 566
 *  杨辉三角
 *
 * @Author Mr Wu    yewen.wu.china@gmail.com
 * Update History:
 * Author        Time            Content
 */
public class Topic118 {

    public static void main(String[] args) {
        System.out.println(generate(5));
    }

    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> result = new ArrayList<>();
        for(int i = 0; i < numRows; i++) {
            List<Integer> rowList = new ArrayList<>();
            for(int j = 0; j <= i; j ++) {
                if (j == 0 || j == i) {
                    rowList.add(1);
                } else {
                    rowList.add(result.get(i-1).get(j-1) + result.get(i-1).get(j));
                }
            }
            result.add(rowList);
        }
        return result;

    }
}
